import request from "../request"
export class UserPostService {
    nextUrl = "";
    refreshUrl = "";
    async GetAsync({id}){
        let json = await request({
            url: `/api/userpost/${id}/`,
            type: "GET",
            params: {
            }
        })
        return json.result
    }
    async List({keyword = "", collectionId, category}) {
        //列表搜索
        var query = {
            keyword: keyword
        };
        if (collectionId) {
            query.collectionId = collectionId
        }
        if(category){
            query.category = category
        }
        let json = await request({
            url: '/api/userpost/',
            type: "GET",
            params: {
                q: JSON.stringify(query)
            }
        })
        this.refreshUrl = json.links.refresh.url;
        this.nextUrl = json.links.next.url;
        return json.result
    }
    async Next() {
        //加载下一页
        let json = await request({
            url: this.nextUrl,
            type: "GET"
        })
        this.refreshUrl = json.links.refresh.url;
        this.nextUrl = json.links.next.url;
        return json.result;
    }
    async Refresh() {
        //刷新
        let json = await request({
            url: this.refreshUrl,
            type: "GET"
        })
        this.refreshUrl = json.links.refresh.url;
        this.nextUrl = json.links.next.url;
        return json.result;
    }
}



